//package nl.hva.three2learn.controller;
//
//import java.util.List;
//
//import javax.servlet.http.HttpSession;
//
//import nl.hva.three2learn.dao.MessageDao;
//import nl.hva.three2learn.dao.UserDao;
//import nl.hva.three2learn.model.Message;
//import nl.hva.three2learn.model.User;
//import nl.hva.three2learn.util.SessionAttributeHelper;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.servlet.ModelAndView;
//
//@Controller
//@RequestMapping(value = "/chat")
//public final class ChatControllerbackup {
//	
//	private static final Logger logger = LoggerFactory.getLogger(ChatControllerbackup.class);
//	
//	@Autowired
//	private UserDao userDao;
//	
//	@Autowired
//	private MessageDao messageDao;
//	
//	@RequestMapping(value = "/")
//	public ModelAndView home() {
//		return new ModelAndView("chat/home");
//	}
//
//	@RequestMapping(value = "/send")
//	public void send(HttpSession session, 
//			@RequestParam("user") long userId,
//			@RequestParam("message") String text) {
//		
//		User sender = (User) session.getAttribute(SessionAttributeHelper.USER);
//		
//		// User isn't logged in
//		if (sender == null) {
//			logger.error("Non-logged on user trying to send message");
//			return;
//		}
//		
//		User receiver = userDao.findById(userId);
//		
//		if (receiver == null) {
//			logger.error("Can't send message to non-existing user {}", userId);
//			return;
//		}
//		
//		// Save the message that was send
//		messageDao.save(new Message(sender, receiver, text));
//	}
//	
//	@RequestMapping(value = "/receive")
//	public @ResponseBody List<Message> receive(HttpSession session,
//						@RequestParam("lastMessageTimestamp") long lastMessageTimestamp,
//						@RequestParam("partner") long partnerId) {
//		
//		User sender = userDao.findById(partnerId);
//		
//		if (sender == null) {
//			logger.error("Sender with id: {} doesn't exist", partnerId);
//			return null;
//		}
//		
//		User user = (User) session.getAttribute(SessionAttributeHelper.USER);
//		
//		List<Message> messages = messageDao.findBySenderAndReceiver(sender, user);
//		
//		return messages;
//	}
//	
//	@RequestMapping(value = "/users")
//	public @ResponseBody List<User> users(HttpSession session) {
//		return userDao.findAllActiveUsers();
//	}
//}
